package com.seabook.easymailservice;

import java.util.Properties;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;

public class GeneralMailer extends AbstractMessageSender {
	
	public void initDefaultMailSender() {
		if (sender == null) {
			sender = new JavaMailSenderImpl();
			sender.setHost("smtp.163.com");
			sender.setPort(25);
			sender.setUsername("ebay_work_mailbox@163.com");
			sender.setPassword("cbk@eBay");
			Properties javaMailProperties = new Properties();
			javaMailProperties.setProperty("mail.smtp.auth", "true");
			sender.setJavaMailProperties(javaMailProperties);
		}
	}
	
	public void sendMessage() throws MessagingException {
		MimeMessage msg = sender.createMimeMessage();
		MimeMessageHelper helper = new MimeMessageHelper(msg, true, "utf-8");
		helper.setTo(tos);
		helper.setCc(ccs);
		helper.setFrom(from);
		helper.setSubject(subject);
		if(isHtml) {
			helper.setText(content, true);
		} else
			helper.setText(content, false);
		sender.send(msg);
	}

}
